// 过滤路由
export const filterMenuRoutes = (routes) => {
  if (!Array.isArray(routes)) return [];

  return routes.reduce((acc, route) => {
    const { meta, children, path, name, redirect, component } = route;

    // 如果当前路由自身可显示（isShow: true），则保留它，并递归处理其子路由
    if (meta?.isShow === true) {
      const filteredRoute = { path, name, meta, redirect, component };

      if (children && children.length > 0) {
        filteredRoute.children = filterMenuRoutes(children);
      }

      acc.push(filteredRoute);
    }
    // 如果当前路由自身不可显示，但它的子路由中有可显示的，也尝试提取子路由
    else if (children && children.length > 0) {
      const childMenus = filterMenuRoutes(children);
      acc.push(...childMenus); // 将子路由中可显示的，提升为菜单项
    }

    return acc;
  }, []);
}